/**
 * Created by CherishTender on 2017/2/25.
 */
// 初始化菜单
$(function() {
	publicAjax('menu/queryMenuByEmployee', {
		//		employeeId: 'D85A74FE-77AA-425B-ACAF-7E92E05F1D25'
	}, function(data) {
		$(".side-menu").html("<li class='menu-header'>操作菜单</li>");
		if(data.data && data.data.length > 0) initMenu(data.data, $(".side-menu"));
		$(".side-menu > li").addClass("menu-item");
		/*获取菜单icon随机色*/
		getMathColor();
	})
	/*获取皮肤*/
	//getSkinByCookie();
	/*菜单json*/
	var menu = [
		//      {"id":"1","name":"操作菜单","parentId":"0","href":"","icon":"","order":"1","isHeader":"1",
		//          "children":[
		{
			"menuId": "11",
			"name": "sdfdfsdfsdfsd1",
			"parentId": "1",
			"href": "modules/common/stanby.html",
			"icon": "common/img/icon_xiangmuxinxin.png",
			"menuOrder": "1",
			"isHeader": "0",
			"children": [],
			"option": ''
		},
		{
			"menuId": "12",
			"name": "项目管理",
			"parentId": "1",
			"href": "",
			"icon": "&#xe604;",
			"menuOrder": "2",
			"isHeader": "0",
			"option": '',
			"children": [{
					"menuId": "4",
					"name": "项目信息",
					"parentId": "12",
					"href": "modules/projectmanage/index.html",
					"icon": "common/img/icon_xiangmuxinxin.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "人员管理",
					"parentId": "12",
					"href": "modules/projectmanage/personalManage.html",
					"icon": "common/img/icon_renyuangl.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "角色管理",
					"parentId": "12",
					"href": "modules/projectmanage/roleManage.html",
					"icon": "common/img/icon_juesegl.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "权限管理",
					"parentId": "12",
					"href": "modules/projectmanage/authorizeManage.html",
					"icon": "common/img/icon_quanxiangl.png",
					"menuOrder": "4",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				}
			]
		},
		{
			"menuId": "13",
			"name": "隧道监测",
			"parentId": "1",
			"href": "",
			"icon": "&#xe604;",
			"menuOrder": "3",
			"isHeader": "0",
			"option": '',
			"children": [{
					"menuId": "4",
					"name": "隧道概况",
					"parentId": "13",
					"href": "modules/curve/index.html",
					"icon": "common/img/icon_suidaogk.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "数据查看",
					"parentmenuId": "13",
					"href": "modules/curve/showdata.html",
					"icon": "common/img/icon_shujuchakan.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "数据分析",
					"parentmenuId": "13",
					"href": "modules/curve/dataanalyse.html",
					"icon": "common/img/icon_shujufenxi.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "预警管理",
					"parentmenuId": "13",
					"href": "modules/curve/alarm.html",
					"icon": "common/img/icon_yujinggl.png",
					"menuOrder": "4",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "监测报告",
					"parentmenuId": "13",
					"href": "modules/curve/report.html",
					"icon": "common/img/icon_jiancebaogao.png",
					"menuOrder": "5",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				}
			]
		},
		{
			"menuId": "14",
			"name": "桥墩监测",
			"parentmenuId": "1",
			"href": "",
			"icon": "&#xe602;",
			"menuOrder": "4",
			"isHeader": "0",
			"option": '',
			"children": [{
					"menuId": "4",
					"name": "桥墩概况",
					"parentmenuId": "14",
					"href": "modules/pier/index.html",
					"icon": "common/img/icon_qiaodungk.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "数据查看",
					"parentmenuId": "14",
					"href": "modules/pier/showdata.html",
					"icon": "common/img/icon_shujuchakan.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "数据分析",
					"parentmenuId": "14",
					"href": "modules/pier/dataanalyse.html",
					"icon": "common/img/icon_shujufenxi.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "预警管理",
					"parentmenuId": "14",
					"href": "modules/pier/alarm.html",
					"icon": "common/img/icon_yujinggl.png",
					"menuOrder": "4",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "监测报告",
					"parentmenuId": "14",
					"href": "modules/pier/report.html",
					"icon": "common/img/icon_jiancebaogao.png",
					"menuOrder": "5",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				}
			]
		},
		//               {"menuId":"15","name":"基坑监测","parentmenuId":"1","href":"","icon":"&#xe602;","order":"1","isHeader":"0",
		//                  "children":[
		//                      {"menuId":"4","name":"基坑概况","parentmenuId":"15","href":"modules/jikeng/map.html","icon":"","order":"1","isHeader":"0","children":""},
		//                      {"menuId":"5","name":"数据查看","parentmenuId":"15","href":"modules/jikeng/showdata.html","icon":"","order":"1","isHeader":"0","children":""},
		//                      {"menuId":"5","name":"数据分析","parentmenuId":"15","href":"modules/jikeng/dataanalyse.html","icon":"","order":"1","isHeader":"0","children":""},
		//                      {"menuId":"5","name":"预警管理","parentmenuId":"15","href":"modules/jikeng/alarm.html","icon":"","order":"1","isHeader":"0","children":""},
		//                      {"menuId":"5","name":"监测报告","parentmenuId":"15","href":"modules/jikeng/report.html","icon":"","order":"1","isHeader":"0","children":""}                    
		//              ]},

		{
			"menuId": "15",
			"name": "基坑监测",
			"parentmenuId": "1",
			"href": "",
			"icon": "&#xe602;",
			"menuOrder": "5",
			"isHeader": "0",
			"option": '',
			"children": [
				//                  {"menuId":"4","name":"基坑概况","parentmenuId":"15","href":"modules/jikeng/map.html","icon":"","order":"1","isHeader":"0","children":""},
				//                      {"menuId":"5","name":"数据查看","parentmenuId":"15","href":"modules/jikeng/showdata.html","icon":"","order":"1","isHeader":"0","children":""},
				//                      {"menuId":"5","name":"数据分析","parentmenuId":"15","href":"modules/jikeng/dataanalyse.html","icon":"","order":"1","isHeader":"0","children":""},
				//                      {"menuId":"5","name":"预警管理","parentmenuId":"15","href":"modules/jikeng/alarm.html","icon":"","order":"1","isHeader":"0","children":""},
				//                      {"menuId":"5","name":"监测报告","parentmenuId":"15","href":"modules/jikeng/report.html","icon":"","order":"1","isHeader":"0","children":""}
				{
					"menuId": "4",
					"name": "基坑概况",
					"parentmenuId": "15",
					"href": "modules/jikeng/index.html",
					"icon": "common/img/icon_jikenggk.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "数据查看",
					"parentmenuId": "15",
					"href": "modules/jikeng/showdata.html",
					"icon": "common/img/icon_shujuchakan.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "数据分析",
					"parentmenuId": "15",
					"href": "modules/jikeng/dataanalyse.html",
					"icon": "common/img/icon_shujufenxi.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "预警管理",
					"parentmenuId": "15",
					"href": "modules/jikeng/alarm.html",
					"icon": "common/img/icon_yujinggl.png",
					"menuOrder": "4",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "监测报告",
					"parentmenuId": "15",
					"href": "modules/jikeng/report.html",
					"icon": "common/img/icon_jiancebaogao.png",
					"menuOrder": "5",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				}
			]
		},
		{
			"menuId": "16",
			"name": "塔吊监测",
			"parentmenuId": "1",
			"href": "",
			"icon": "&#xe602;",
			"menuOrder": "6",
			"isHeader": "0",
			"option": '',
			"children": [{
					"menuId": "4",
					"name": "实时监测",
					"parentmenuId": "16",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_shishijiance.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": "",
					"option": ''
				},
				{
					"menuId": "5",
					"name": "运行数据",
					"parentmenuId": "16",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_yunxingshuju.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": "",
					"option": ''
				},
				{
					"menuId": "5",
					"name": "预警管理",
					"parentmenuId": "16",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_yujinggl.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": "",
					"option": ''
				},
				{
					"menuId": "5",
					"name": "统计信息",
					"parentmenuId": "16",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_tongjixinxin.png",
					"menuOrder": "4",
					"isHeader": "0",
					"children": "",
					"option": ''
				},
			]
		},
		{
			"menuId": "17",
			"name": "架桥机监测",
			"parentmenuId": "1",
			"href": "",
			"icon": "&#xe602;",
			"menuOrder": "7",
			"isHeader": "0",
			"children": [{
					"menuId": "4",
					"name": "实时监测",
					"parentmenuId": "17",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_shishijiance.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "运行数据",
					"parentmenuId": "17",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_yunxingshuju.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "预警管理",
					"parentmenuId": "17",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_yujinggl.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "统计信息",
					"parentmenuId": "17",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_tongjixinxin.png",
					"menuOrder": "4",
					"isHeader": "0",
					"children": ""
				},
			]
		},
		{
			"menuId": "18",
			"name": "机械设备监测",
			"parentmenuId": "1",
			"href": "",
			"icon": "&#xe602;",
			"menuOrder": "8",
			"isHeader": "0",
			"children": [{
					"menuId": "4",
					"name": "实时监测",
					"parentmenuId": "18",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_shishijiance.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "运行数据",
					"parentmenuId": "18",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_yunxingshuju.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "预警管理",
					"parentmenuId": "18",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_yujinggl.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "统计信息",
					"parentmenuId": "18",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_tongjixinxin.png",
					"menuOrder": "4",
					"isHeader": "0",
					"children": ""
				}
			]
		},
		{
			"menuId": "19",
			"name": "配电柜监测",
			"parentmenuId": "1",
			"href": "",
			"icon": "&#xe602;",
			"menuOrder": "9",
			"isHeader": "0",
			"children": [{
					"menuId": "4",
					"name": "实时监测",
					"parentmenuId": "19",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_shishijiance.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "用电量统计",
					"parentmenuId": "19",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_tongjixinxin.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "实时功率图",
					"parentmenuId": "19",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_tongjixinxin.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "合闸状态监测",
					"parentmenuId": "19",
					"href": "modules/common/stanby.html",
					"icon": "",
					"menuOrder": "4",
					"isHeader": "0",
					"children": ""
				},
			]
		},

		{
			"menuId": "20",
			"name": "监测设置",
			"parentmenuId": "1",
			"href": "",
			"icon": "&#xe602;",
			"menuOrder": "10",
			"isHeader": "0",
			"option": '',
			"children": [{
					"menuId": "4",
					"name": "隧道设置",
					"parentmenuId": "20",
					"href": "modules/measuremanage/curve.html",
					"icon": "common/img/icon_suidaoshezhi.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "桥墩设置",
					"parentmenuId": "20",
					"href": "modules/measuremanage/pierset.html",
					"icon": "common/img/icon_qiaodunshezhi.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "基坑设置",
					"parentmenuId": "20",
					"href": "modules/measuremanage/foundationditchset.html",
					"icon": "common/img/icon_jikengshezhi.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				//                      {"menuId":"5","name":"基坑设置","parentmenuId":"20","href":"modules/measuremanage/foundationditchset.html","icon":"","order":"1","isHeader":"0","children":""},
				{
					"menuId": "5",
					"name": "场景设置",
					"parentmenuId": "20",
					"href": "modules/measuremanage/scene.html",
					"icon": "common/img/icon_changjingshezhi.png",
					"menuOrder": "4",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
			]
		},

		{
			"menuId": "21",
			"name": "设备管理",
			"parentmenuId": "1",
			"href": "",
			"icon": "&#xe602;",
			"menuOrder": "11",
			"isHeader": "0",
			"children": [{
					"menuId": "4",
					"name": "塔吊管理",
					"parentmenuId": "21",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_tadiaogl.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "架桥机管理",
					"parentmenuId": "21",
					"href": "modules/common/stanby.html",
					"icon": "",
					"menuOrder": "2",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "机械设备管理",
					"parentmenuId": "21",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_jixieshebeigl.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "配电柜管理",
					"parentmenuId": "21",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_peidianguigl.png",
					"menuOrder": "4",
					"isHeader": "0",
					"children": ""
				},
			]
		},

		{
			"menuId": "22",
			"name": "系统管理",
			"parentmenuId": "1",
			"href": "",
			"icon": "&#xe602;",
			"menuOrder": "12",
			"isHeader": "0",
			"option": '',
			"children": [{
					"menuId": "4",
					"name": "领域设置",
					"parentmenuId": "22",
					"href": "modules/systemset/fieldmanage.html",
					"icon": "common/img/icon_lingyushezhi.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "采集设备",
					"parentmenuId": "22",
					"href": "modules/systemset/equipmanage.html",
					"icon": "common/img/icon_caijishebei.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "测量仪器",
					"parentmenuId": "22",
					"href": "modules/systemset/measuremanage.html",
					"icon": "common/img/icon_celiangyiqi.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "黑匣子管理",
					"parentmenuId": "22",
					"href": "modules/systemset/boxmanage.html",
					"icon": "common/img/icon_heixiazi.png",
					"menuOrder": "4",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
				{
					"menuId": "5",
					"name": "菜单管理",
					"parentmenuId": "22",
					"href": "modules/systemset/menumanage.html",
					"icon": "common/img/icon_caidangl.png",
					"menuOrder": "5",
					"isHeader": "0",
					"children": "",
					"option": [1,2,3]
				},
			]
		},

		{
			"menuId": "23",
			"name": "技术管理",
			"parentmenuId": "1",
			"href": "",
			"icon": "",
			"menuOrder": "13",
			"isHeader": "0",
			"children": [{
					"menuId": "4",
					"name": "隧道资料",
					"parentmenuId": "23",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_ziliao1.png",
					"menuOrder": "1",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "桥梁资料",
					"parentmenuId": "23",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_ziliao2.png",
					"menuOrder": "2",
					"isHeader": "0",
					"children": ""
				},
				{
					"menuId": "5",
					"name": "基坑资料",
					"parentmenuId": "23",
					"href": "modules/common/stanby.html",
					"icon": "common/img/icon_ziliao3.png",
					"menuOrder": "3",
					"isHeader": "0",
					"children": ""
				},
			]
		},

		{
			"menuId": "24",
			"name": "第三方应用",
			"parentmenuId": "1",
			"href": "modules/common/stanby.html",
			"icon": "common/img/ic_3Application2.png",
			"menuOrder": "14",
			"isHeader": "0",
			"children": []
		},

		//      ]}
	];
//	$(".side-menu").html("<li class='menu-header'>操作菜单</li>");
//	initMenu(menu, $(".side-menu"));
//	$(".side-menu > li").addClass("menu-item");
//	/*获取菜单icon随机色*/
//	getMathColor();
});
/*循环菜单*/
function initMenu(menu, parent) {
//	function sortId(a, b) {
//		return a.menuOrder - b.menuOrder
//	}
//	menu.sort(sortId);
	store.set('optType','');
	for(var i = 0; i < menu.length; i++) {
		var item = menu[i];
		var str = ''
		var option = item.option ? item.option.join(',') : '';
		if(item.name == '项目主页') {
			if(item.icon == "") {
				item.icon = "&#xe610"
				str = "<li><a href='" + item.href + "' data-option='" + option + "'><i class='icon-font'>" + item.icon + "</i><span>" + item.name + "</span></a></li>";
			} else {
				if((item.icon).indexOf('common') == 0) {
					item.icon = item.icon;
				} else {
					item.icon = "/olm/file/" + item.icon
				}
				str = "<li><a href='" + item.href + "' data-option='" + option + "'><img src='" + item.icon + "' /><span>" + item.name + "</span></a></li>";
			}
			$(parent).append(str);
		} else if(!item.children || item.children.length == 0) {
			if(item.icon == "") {
				item.icon = "&#xe610"
				str = "<li  data-menuid='" + item.menuId + "' ><a href='" + item.href + "'  data-menuid='" + item.menuId + "' data-option='" + option + "'><i class='icon-font'>" + item.icon + "</i><span>" + item.name + "</span></a></li>";
			} else {
				if((item.icon).indexOf('common') == 0) {
					item.icon == item.icon;
				} else {
					item.icon = "/olm/file/" + item.icon
				}
				str = "<li  data-menuid='" + item.menuId + "' ><a href='" + item.href + "' data-menuid='" + item.menuId + "' data-option='" + option + "'><img src='" + item.icon + "' /><span>" + item.name + "</span></a></li>";
			}
			$(parent).append(str);
		} else {
			var src_left;
			if(item.icon == "") {
				src_left = "&#xe610"
			} else {
				if((item.icon).indexOf('common') == 0) {
					src_left = item.icon;
				} else {
					isrc_left = "/olm/file/" + item.icon
				}
			}
			str = "<li data-menuid='"+item.menuId+"'><a data-id='" + item.menuId + "' data-option='" + option + "'><img class='img_left_icon' src='" + src_left + "' /><span>" + item.name + "</span><img class='img_right_icon' src='common/images/arrow_right.png' /></a>";
			str += "<ul class='menu-item-child' id='menu-child-" + item.menuId + "'></ul></li>";
			$(parent).append(str);
			var childParent = $("#menu-child-" + item.menuId);
			initMenu(item.children, childParent);
		}
	}
}
// *随机颜色*/
function getMathColor() {
	var arr = new Array();
	arr[0] = "#ffac13";
	arr[1] = "#83c44e";
	arr[2] = "#2196f3";
	arr[3] = "#e53935";
	arr[4] = "#00c0a5";
	arr[5] = "#16A085";
	arr[6] = "#ee3768";

	var le = $(".menu-item > a").length;
	for(var i = 0; i < le; i++) {
		var num = Math.round(Math.random() * 5 + 1);
		var color = arr[num - 1];
		$(".menu-item > a").eq(i).find("i:first").css("color", color);
	}
}

// 选择“.side-menu”下的所有的 li下的所有a标签
$(".side-menu").on('click', 'li a', function(e) {
	var animationSpeed = 300;
	var $this = $(this);
	var name = $this.find('span').text();
	var checkElement = $this.next(); //这个函数只返回后面那个紧邻的同辈元素
	store.set('optType',$this.attr("data-option"));
	if($this.attr("data-id")){
		$(".img_right_icon").attr('src', 'common/images/arrow_right.png');
		$(".side-menu .menu-item a>.img_right_icon").css('margin-top', '6px')
	}else{
		$(".side-menu li").removeClass('selected_a');
	}
	$(this).parent("li").addClass('selected_a');
	if(checkElement.is('.menu-item-child') && checkElement.is(':visible')) {
		checkElement.slideUp(animationSpeed, function() {
			checkElement.removeClass('menu-open');
		});
		checkElement.parent("li").removeClass("active");
	}
	//如果菜单是不可见的
	else if((checkElement.is('.menu-item-child')) && (!checkElement.is(':visible'))) {
		//获取上级菜单
		var parent = $this.parents('ul').first();
		//从父级开始找所有打开的菜单并关闭
		var ul = parent.find('ul:visible').slideUp(animationSpeed);
		//在父级中移出menu-open标记
		ul.removeClass('menu-open');
		//获取父级li
		var parent_li = $this.parent("li");
		//打开菜单时添加menu-open标记
		checkElement.slideDown(animationSpeed, function() {
			//添加样式active到父级li
			checkElement.addClass('menu-open');
			parent.find('li.active').removeClass('active');
			parent_li.addClass('active');
			if($this.attr("data-id")){
				$(".active .img_right_icon").attr('src', 'common/images/arrow_down2.png');
				$(".side-menu .active a>.img_right_icon").css('margin-top', '10px');
			}	
		});
	}
	//防止有链接跳转
	e.preventDefault();

	addIframe($this);
});
/*添加iframe*/
function addIframe(cur) {
	//关闭所有页面
	$(".tab-nav-content a").each(function(i, e) {
			if(i != 0) {
				$(e).remove();
			}
	});
	
	$("#layout-main-body iframe").each(function(i, e) {
			if(i != 0) {
				$(e).remove();
			}
	});
	var $this = cur;
	var h = $this.attr("href"),
		m = $this.data("index"),
		t = $this.data("option"),
		label = $this.find("span").text(),
		isHas = false,
		pid =$this.parent().parent().prev().data("id") ,
		id = $this.data("menuid");
		//alert($this.parent().parent().prev().data("id"));
	if(h == "" || $.trim(h).length == 0) {
		return false;
	}
	//将点击的菜单di存放于session中用于日志
	$.ajax({
		type:'post',
		url:"/olm/saveMenu",
		data:{"id":id},
		success:function(r){
			
		}
	})
	
	var idsss = h.substr(h.indexOf('/') + 1).replace(/\//g,'');
	idsss = idsss.substr(0, idsss.indexOf('.'));
	// console.log(idsss)
	var fullWidth = $(window).width();
	if(fullWidth >= 750) {
		$(".layout-side").show();
	} else {
		$(".layout-side").hide();
	}

	$(".content-tab").each(function() {
		if($(this).data("id") == h) {
			if(!$(this).hasClass("active")) {
				$(this).addClass("active").siblings(".content-tab").removeClass("active");
				addTab(this);
			}
			isHas = true;
		}
	});
	if(isHas) {
		$(".body-iframe").each(function() {
			if($(this).data("id") == h) {
				$(this).show().siblings(".body-iframe").hide();
			}
		});
	}
	if(!isHas) {
		var tab = "<a href='javascript:;' class='content-tab active' data-id='" + h + "'  data-openid='" + id + "'  data-openpid='" + pid + "'>" + label + " <i class='icon-font'>&#xe617;</i></a>";
		$(".content-tab").removeClass("active");
		$(".tab-nav-content").append(tab);
		var iframe = "<iframe data-flag='"+id+"' id='" + idsss + "' data-option='"+t+"' class='body-iframe' name='iframe" + m + "' width='100%' height='99%' src='" + h + "' frameborder='0' data-id='" + h + "' seamless></iframe>";
		$(".layout-main-body").find("iframe.body-iframe").hide().parents(".layout-main-body").append(iframe);
		addTab($(".content-tab.active"));
	}
	return false;
}

/*添加tab*/
function addTab(cur) {
	
	var prev_all = tabWidth($(cur).prevAll()),
		next_all = tabWidth($(cur).nextAll());
	var other_width = tabWidth($(".layout-main-tab").children().not(".tab-nav"));
	var navWidth = $(".layout-main-tab").outerWidth(true) - other_width; //可视宽度
	var hidewidth = 0;
	if($(".tab-nav-content").width() < navWidth) {
		hidewidth = 0
	} else {
		if(next_all <= (navWidth - $(cur).outerWidth(true) - $(cur).next().outerWidth(true))) {
			if((navWidth - $(cur).next().outerWidth(true)) > next_all) {
				hidewidth = prev_all;
				var m = cur;
				while((hidewidth - $(m).outerWidth()) > ($(".tab-nav-content").outerWidth() - navWidth)) {
					hidewidth -= $(m).prev().outerWidth();
					m = $(m).prev()
				}
			}
		} else {
			if(prev_all > (navWidth - $(cur).outerWidth(true) - $(cur).prev().outerWidth(true))) {
				hidewidth = prev_all - $(cur).prev().outerWidth(true)
			}
		}
	}
	$(".tab-nav-content").animate({
			marginLeft: 0 - hidewidth + "px"
		},
		"fast")
}

/*获取宽度*/
function tabWidth(tabarr) {
	var allwidth = 0;
	$(tabarr).each(function() {
		allwidth += $(this).outerWidth(true)
	});
	return allwidth;
}
/*左按钮事件*/
$(".btn-left").on("click", leftBtnFun);
/*右按钮事件*/
$(".btn-right").on("click", rightBtnFun);
/*选项卡切换事件*/
$(".tab-nav-content").on("click", ".content-tab", navChange);
/*选项卡关闭事件*/
$(".tab-nav-content").on("click", ".content-tab i", closePage);
/*选项卡双击关闭事件*/
$(".tab-nav-content").on("dblclick", ".content-tab", closePage);

/*左按钮方法*/
function leftBtnFun() {
	var ml = Math.abs(parseInt($(".tab-nav-content").css("margin-left")));
	var other_width = tabWidth($(".layout-main-tab").children().not(".tab-nav"));
	var navWidth = $(".layout-main-tab").outerWidth(true) - other_width; //可视宽度
	var hidewidth = 0;
	if($(".tab-nav-content").width() < navWidth) {
		return false
	} else {
		var tabIndex = $(".content-tab:first");
		var n = 0;
		while((n + $(tabIndex).outerWidth(true)) <= ml) {
			n += $(tabIndex).outerWidth(true);
			tabIndex = $(tabIndex).next();
		}
		n = 0;
		if(tabWidth($(tabIndex).prevAll()) > navWidth) {
			while((n + $(tabIndex).outerWidth(true)) < (navWidth) && tabIndex.length > 0) {
				n += $(tabIndex).outerWidth(true);
				tabIndex = $(tabIndex).prev();
			}
			hidewidth = tabWidth($(tabIndex).prevAll());
		}
	}
	$(".tab-nav-content").animate({
			marginLeft: 0 - hidewidth + "px"
		},
		"fast");
}

/*右按钮方法*/
function rightBtnFun() {
	var ml = Math.abs(parseInt($(".tab-nav-content").css("margin-left")));
	var other_width = tabWidth($(".layout-main-tab").children().not(".tab-nav"));
	var navWidth = $(".layout-main-tab").outerWidth(true) - other_width; //可视宽度
	var hidewidth = 0;
	if($(".tab-nav-content").width() < navWidth) {
		return false
	} else {
		var tabIndex = $(".content-tab:first");
		var n = 0;
		while((n + $(tabIndex).outerWidth(true)) <= ml) {
			n += $(tabIndex).outerWidth(true);
			tabIndex = $(tabIndex).next();
		}
		n = 0;
		while((n + $(tabIndex).outerWidth(true)) < (navWidth) && tabIndex.length > 0) {
			n += $(tabIndex).outerWidth(true);
			tabIndex = $(tabIndex).next()
		}
		hidewidth = tabWidth($(tabIndex).prevAll());
		if(hidewidth > 0) {
			$(".tab-nav-content").animate({
					marginLeft: 0 - hidewidth + "px"
				},
				"fast");
		}
	}
}

/*选项卡切换方法*/
function navChange() {
	$(".menu-item-child li").removeClass('selected_a');
	if(!$(this).hasClass("active")) {
		var k = $(this).data("id");
		$('a[href="'+k+'"]').parent().addClass('selected_a');
		
		$(".body-iframe").each(function() {
			if($(this).data("id") == k) {
				$(this).show().siblings(".body-iframe").hide();
				return false
			}
		});
		$(this).addClass("active").siblings(".content-tab").removeClass("active");
		addTab(this);
	}
}

/*选项卡关闭方法*/
function closePage() {
	var url = $(this).parents(".content-tab").data("id");
	$('a[href="'+url+'"]').parent().removeClass('selected_a');
	var cur_width = $(this).parents(".content-tab").width();
	if($(this).parents(".content-tab").hasClass("active")) {
		if($(this).parents(".content-tab").next(".content-tab").size()) {
			var next_url = $(this).parents(".content-tab").next(".content-tab:eq(0)").data("id");
			$('a[href="'+next_url+'"]').parent().addClass('selected_a');
			$(this).parents(".content-tab").next(".content-tab:eq(0)").addClass("active");
			$(".body-iframe").each(function() {
				if($(this).data("id") == next_url) {
					$(this).show().siblings(".body-iframe").hide();
					return false
				}
			});
			var n = parseInt($(".tab-nav-content").css("margin-left"));
			if(n < 0) {
				$(".tab-nav-content").animate({
						marginLeft: (n + cur_width) + "px"
					},
					"fast")
			}
			$(this).parents(".content-tab").remove();
			$(".body-iframe").each(function() {
				if($(this).data("id") == url) {
					$(this).remove();
					return false
				}
			})
		}
		if($(this).parents(".content-tab").prev(".content-tab").size()) {
			var prev_url = $(this).parents(".content-tab").prev(".content-tab:last").data("id");
			$('a[href="'+prev_url+'"]').parent().addClass('selected_a');
			$(this).parents(".content-tab").prev(".content-tab:last").addClass("active");
			$(".body-iframe").each(function() {
				if($(this).data("id") == prev_url) {
					$(this).show().siblings(".body-iframe").hide();
					return false
				}
			});
			$(this).parents(".content-tab").remove();
			$(".body-iframe").each(function() {
				if($(this).data("id") == url) {
					$(this).remove();
					return false
				}
			})
		}
	} else {
		$(this).parents(".content-tab").remove();
		$(".body-iframe").each(function() {
			if($(this).data("id") == url) {
				$(this).remove();
				return false
			}
		});
		addTab($(".content-tab.active"))
	}
	return false
}

/*左侧菜单展开和关闭按钮事件*/
$(document).on("click", ".layout-side-arrow", function() {
	if($(".layout-side").hasClass("close")) {
		$(".layout-side").removeClass("close");
		$(".layout-main").removeClass("full-page");
		$(".layout-footer").removeClass("full-page");
		$(this).removeClass("close");
		$(".layout-side-arrow-icon").removeClass("close");
	} else {
		$(".layout-side").addClass("close");
		$(".layout-main").addClass("full-page");
		$(".layout-footer").addClass("full-page");
		$(this).addClass("close");
		$(".layout-side-arrow-icon").addClass("close");
	}
});
/*左侧菜单响应式*/
$(window).resize(function() {
	var width = $(this).width();
	if(width >= 750) {
		$(".layout-side").show();
	} else {
		$(".layout-side").hide();
	}
});
/*头部菜单按钮点击事件*/
$(".header-menu-btn").click(function(){
  /*$(".layout-side").removeClass("close");
  $(".layout-main").removeClass("full-page");
  $(".layout-footer").removeClass("full-page");
  $(".layout-side-arrow").removeClass("close");
  $(".layout-side-arrow-icon").removeClass("close");
  $(".layout-side").slideToggle();*/
  $(".header-dropdown-menu.right").slideToggle();
});

/*头部下拉框移入移出*/
$(document).on("mouseenter", ".header-bar-nav", function() {
	$(this).addClass("open");
});
$(document).on("mouseleave", ".header-bar-nav", function() {
	$(this).removeClass("open");
});

/*皮肤选择*/
$(".dropdown-skin li a").click(function() {
	var v = $(this).attr("data-val");
	var hrefStr = $("#layout-skin").attr("href");
	var hrefRes = hrefStr.substring(0, hrefStr.lastIndexOf('skin/')) + 'skin/' + v + '/skin.css';
	$(window.frames.document).contents().find("#layout-skin").attr("href", hrefRes);
	setCookie("scclui-skin", v);
});
// *获取cookie中的皮肤*/
function getSkinByCookie() {
	var v = getCookie("scclui-skin");
	var hrefStr = $("#layout-skin").attr("href");
	if(v == null || v == "") {
		v = "qingxin";
	}
	if(hrefStr != undefined) {
		var hrefRes = hrefStr.substring(0, hrefStr.lastIndexOf('skin/')) + 'skin/' + v + '/skin.css';
		$("#skin").attr("href", hrefRes);
	}
}
/*设置cookie*/
function setCookie(name, value, days) {
	if(days == null || days == '') {
		days = 300;
	}
	var exp = new Date();
	exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
	document.cookie = name + "=" + escape(value) + "; path=/;expires=" + exp.toGMTString();
}

/*获取cookie*/
function getCookie(name) {
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	if(arr = document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;
}

/*ajax请求*/
function ajax(url, param, datat, callback) {
	$.ajax({
		type: "post",
		url: url,
		data: param,
		dataType: datat,
		success: function(data) {
			callback;
		},
		error: function() {
			alert("失败..");
		}
	});
}

function showCurrentDate() {
	var today, hour, second, minute, year, month, date;
	var strDate;
	today = new Date();
	var n_day = today.getDay();
	switch(n_day) {
		case 0:
			{
				strDate = "星期日"
			}
			break;
		case 1:
			{
				strDate = "星期一"
			}
			break;
		case 2:
			{
				strDate = "星期二"
			}
			break;
		case 3:
			{
				strDate = "星期三"
			}
			break;
		case 4:
			{
				strDate = "星期四"
			}
			break;
		case 5:
			{
				strDate = "星期五"
			}
			break;
		case 6:
			{
				strDate = "星期六"
			}
			break;
		case 7:
			{
				strDate = "星期日"
			}
			break;
	}
	year = today.getYear() + 1900;
	month = today.getMonth() + 1;
	if(month < 10) {
		month = "0" + month;
	}
	date = today.getDate();
	if(date < 10) {
		date = "0" + date;
	}
	hour = today.getHours();
	if(hour < 10) {
		hour = "0" + hour;
	}
	minute = today.getMinutes();
	if(minute < 10) {
		minute = "0" + minute;
	}
	second = today.getSeconds();
	if(second < 10) {
		second = "0" + second;
	}
	$("#currentDate").html(year + "年" + month + "月" + date + "日  " + strDate + "<span style='padding:0 3px'></span>" + hour + ":" + minute + ":" + second); //显示时间
	window.setTimeout('showCurrentDate()', 1000);
}